// 可选参数
function buildName(firstName, lastName) {
    if (lastName)
        return firstName + " " + lastName;
    else
        return firstName;
}
var result1 = buildName("Bob"); // works correctly now
var result2 = buildName("Bob", "Adams", "Sr."); // error, too many parameters
var result3 = buildName("Bob", "Adams"); // ah, just right
// 默认参数
// lastName有默认参数，与可选参数类型一致，默认位置在必选参数后
function buildName1(firstName, lastName) {
    if (lastName === void 0) { lastName = "Smith"; }
    return firstName + " " + lastName;
}
var result11 = buildName1("Bob"); // works correctly now, returns "Bob Smith"
var result21 = buildName1("Bob", undefined); // still works, also returns "Bob Smith"
var result31 = buildName1("Bob", "Adams", "Sr."); // error, too many parameters
var result41 = buildName1("Bob", "Adams"); // ah, just right
// 默认参数在前
// 需要传undefined或者赋值
function buildName2(firstName, lastName) {
    if (firstName === void 0) { firstName = "Will"; }
    return firstName + " " + lastName;
}
var result12 = buildName2("Bob"); // error, too few parameters
var result22 = buildName2("Bob", "Adams", "Sr."); // error, too many parameters
var result32 = buildName2("Bob", "Adams"); // okay and returns "Bob Adams"
var result42 = buildName2(undefined, "Adams"); // okay and returns "Will Adams"
